package selectionSort;

import shellSort.MyShellSort;

import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86187
 * Date: 2022-08-10
 * Time: 14:09
 */

public class TestSelectionSort {

    //测试直接选择排序所用时间
    public static void testSelectSort(int[] array) {
        array = Arrays.copyOf(array,array.length);

        long startTime = System.currentTimeMillis();
        MySelectionSort.selectionSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接选择排序排序耗时:"+(endTime - startTime)+"ms");
        //System.out.println(Arrays.toString(array));

    }

    public static void testSelectSort2(int[] array) {
        array = Arrays.copyOf(array,array.length);

        long startTime1 = System.currentTimeMillis();
        MySelectionSort.selectionSort2(array);
        long endTime1 = System.currentTimeMillis();
        System.out.println("优化后直接选择排序排序耗时:"+(endTime1 - startTime1)+"ms");
        //System.out.println(Arrays.toString(array));

    }

    public static void main(String[] args) {
        int[] array = new int[10_0000];
        //int[] array = {12,1,2,5,71,4,8,2,3,5};
        //initArrayOrder(array);//有序初始化
        initArrayNotOrder(array); //无序初始化

        testSelectSort(array);
        testSelectSort2(array);

        //System.out.println(Arrays.toString(array));
    }

    public static void initArrayOrder(int[] array) {
        //有序的初始化
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }
    public static void initArrayNotOrder(int[] array) {
        //不有序的初始化
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }
}
